<?php
/**
 * Created by 项目.
 * User: xuguopeng
 * Date: 2020-06-15
 * Time: 18:44
 */

namespace app\api\controller\v1;


use app\api\controller\BaseController;
use app\api\model\Price as PriceModel;
use app\api\model\PriceSort;

class Price extends BaseController
{
    protected $beforeActionList = [
        'checkPrimaryScope' => ['only' => 'getPriceSort,getPrice']
    ];

    // 获取分类列表
    public function getPriceSort()
    {
       return PriceSort::order('order_sort desc')->select()->toArray();
    }

    public function getPrice($page,$limit,$sort_id)
    {
        if($sort_id) {
            $query = PriceModel::with('img')->where('sort_id',$sort_id)->order('order_sort desc');
        } else {
            $query = PriceModel::with('img')->order('order_sort desc');
        }
        $count = $query->count();
        $result = $query->page($page, $limit)->select()->toArray();
        $data['count'] = $count;
        $data['data'] = $result;
        return $data;
    }
}